package com.cpone.cloudweb.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateUtil {
    public static SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static SimpleDateFormat formatter_yyyMMdd=new SimpleDateFormat("yyyyMMdd");
    public static SimpleDateFormat formatter_yyyy_mm_dd_hh_mm=new SimpleDateFormat("yyyy-MM-dd HH:mm");
    public static String formatDate(Long time){
        Calendar cal=Calendar.getInstance();
        cal.setTimeInMillis(time);
        return formatter.format(cal.getTime());
    }

    /**
     * 获取昨天 今天 明天字符串
     * @return
     */
    public static List<String> formatDatel(){
        List<String> dateArr=new ArrayList<String>();
        for(int i=0;i<3;i++){
            Calendar cal=Calendar.getInstance();
            cal.add(Calendar.DATE,i-1);
            Date dl=cal.getTime();
            dateArr.add(formatter_yyyMMdd.format(dl));
        }
        return dateArr;
    }

    /**
     * 获取明天字符串
     * @return
     */
    public static String getTomorrowStr(){
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,+1);
        Date dl=cal.getTime();
        return formatter_yyyMMdd.format(dl);
    }

    /**
     * 获取前n分钟的时间
     * @param n
     * @return
     */
    public static String getBeforeMinStr(int n){
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.MINUTE,-n);
        Date dl=cal.getTime();
        return formatter_yyyy_mm_dd_hh_mm.format(dl);
    }

    /**
     * 获取前天字符串
     * @return
     */
    public static String getBeforeYesterdayStr(){
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,-2);
        Date dl=cal.getTime();
        return formatter_yyyMMdd.format(dl);

    }

}
